package com.ht.modules.system.online.codegenerate.generate.util;

import freemarker.cache.FileTemplateLoader;
import freemarker.cache.MultiTemplateLoader;
import freemarker.core.TemplateClassResolver;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class b {
    public static Configuration a(List<File> files, String var1, String var2) throws IOException {
        Configuration configuration = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
        FileTemplateLoader[] var4 = new FileTemplateLoader[files.size()];
        for (int var5 = 0; var5 < files.size(); ++var5) {
            File var6 = files.get(var5);
            var4[var5] = new FileTemplateLoader(var6);
        }
        MultiTemplateLoader var7 = new MultiTemplateLoader(var4);
        configuration.setTemplateLoader(var7);
        configuration.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);
        configuration.setNumberFormat("###############");
        configuration.setBooleanFormat("true,false");
        configuration.setDefaultEncoding(var1);
        return configuration;
    }

    public static List<String> a(String var0, String var1) {
        String[] var2 = b(var0, "\\/");
        List<String> var3 = new ArrayList<>();
        var3.add(var1);
        var3.add(File.separator + var1);
        StringBuilder var4 = new StringBuilder();
        for (String s : var2) {
            var4.append(File.separator).append(s);
            var3.add(var4 + File.separator + var1);
        }
        return var3;
    }

    public static String[] b(String var0, String var1) {
        if (var0 == null) {
            return new String[0];
        }
        StringTokenizer var2 = new StringTokenizer(var0, var1);
        List<String> var3 = new ArrayList<>();
        while (var2.hasMoreElements()) {
            Object var4 = var2.nextElement();
            var3.add(var4.toString());
        }
        return var3.toArray(new String[0]);
    }

    public static String a(String var0, Map<String, Object> codeGenerateInfo, Configuration var2) {
        StringWriter var3 = new StringWriter();

        try {
            Template var4 = new Template("templateString...", new StringReader(var0), var2);
            var4.process(codeGenerateInfo, var3);
            return var3.toString();
        } catch (Exception var5) {
            throw new IllegalStateException("cannot process templateString:" + var0 + " cause:" + var5, var5);
        }
    }

    public static void a(Template template, Map<String, Object> codeGenerateInfo, File file, String var3) throws IOException, TemplateException {
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), var3));
        codeGenerateInfo.put("Format", new SimpleFormat());
        codeGenerateInfo.put("currentDate", NonceUtils.now());
        template.process(codeGenerateInfo, bufferedWriter);
        bufferedWriter.close();
    }
}
